<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>修改机房</title>
    <link rel="stylesheet" th:href="@{/lib/layui-v2.6.3/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/layuimini.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/themes/default.css}" media="all">
    <link rel="stylesheet" th:href="@{/lib/font-awesome-4.7.0/css/font-awesome.min.css}" media="all">
    <style>
        body{
            padding: 10px;
        }
    </style>
</head>
<body>
<form class="layui-form" action="" th:object="${room}">
    <div class="layui-form-item">
        <label class="layui-form-label">机房地址</label>
        <div class="layui-input-block">
            <input type="hidden" th:field="*{RoomId}">
            <input type="text" th:field="*{RoomAddr}" required="required"  lay-verify="required" placeholder="请输入机房地址" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">机房容量</label>
        <div class="layui-input-inline">
            <input type="number" th:field="*{RoomCap}" required="required" lay-verify="required" placeholder="请输入机房容量" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">校区</label>
        <div class="layui-input-block">
            <select name="campus" lay-verify="required">
                <option value="">请选择</option>
                <option value="1" th:selected="${room.Campus} eq '1'">花津校区</option>
                <option value="2" th:selected="${room.Campus} eq '2'">赭山校区</option>
                <option value="3" th:selected="${room.Campus} eq '3'">天门山校区</option>
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">空闲时间</label>
        <div class="layui-input-block">
            <input type="checkbox" name="aempty" title="上午" lay-skin="primary" th:checked="*{Aempty} eq '1'" value="1" class="layui-input">
            <input type="checkbox" name="pempty" title="下午" lay-skin="primary" th:checked="*{Pempty} eq '1'" value="1" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button id="btn-submit" class="layui-btn" lay-submit lay-filter="btn-submit-filter">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>

<script th:src="@{/lib/layui-v2.6.3/layui.js}" charset="utf-8"></script>
<script th:inline="javascript">
    layui.use(['laydate','table','form'],function () {
        var laydate=layui.laydate;
        var table=layui.table;
        var form=layui.form;
        var $=layui.$;

        //表单提交
        form.on('submit(btn-submit-filter)', function(data){
            $("#btn-submit").attr("disabled","disabled").addClass("layui-btn-disabled");
            console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            //异步请求提交数据
            $.ajax({
                url:"/room/edit",
                data:data.field,
                success:function (response) {
                    if(response.state==200){
                        //成功提示
                        layer.msg(response.message, {
                            icon: 1,
                            time: 2000 //2秒关闭（如果不配置，默认是3秒）
                        }, function(){
                            //刷新表格
                            parent.refreshTable();
                            //关闭窗口
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                        });
                    }else {
                        $("#btn-submit").removeAttr("disabled","disabled").addClass("layui-btn-disabled");
                        layer.msg("修改机房失败！", {
                            icon: 2,
                            anim: 6
                        });
                    }
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });
    });
</script>
</body>
</html>